b7b3f8
@@ -276,7 +276,7 @@
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
 
   public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
     String str = new Scanner(x, "UTF-8").useDelimiter("\\A").next();
-    this.parameters.put(parameterIndex, str);
+    setString(parameterIndex, str);
   }
 
   /*
@@ -696,6 +696,27 @@
public void setShort(int parameterIndex, short x) throws SQLException {
     this.parameters.put(parameterIndex,""+x);
   }
 
+  private String replaceBackSlashSingleQuote(String x) {
+    // scrutinize escape pair, specifically, replace \' to '
+    StringBuffer newX = new StringBuffer();
+    for (int i = 0; i < x.length(); i++) {
+      char c = x.charAt(i);
+      if (c == '\\' && i < x.length()-1) {
+        char c1 = x.charAt(i+1);
+        if (c1 == '\'') {
+          newX.append(c1);
+        } else {
+          newX.append(c);
+          newX.append(c1);
+        }
+        i++;
+      } else {
+        newX.append(c);
+      }
+    }
+    return newX.toString();
+  }
+
   /*
    * (non-Javadoc)
    *
@@ -703,8 +724,9 @@
public void setShort(int parameterIndex, short x) throws SQLException {
    */
 
   public void setString(int parameterIndex, String x) throws SQLException {
-     x=x.replace("'", "\\'");
-     this.parameters.put(parameterIndex,"'"+x+"'");
+    x = replaceBackSlashSingleQuote(x);
+    x=x.replace("'", "\\'");
+    this.parameters.put(parameterIndex, "'"+x+"'");
   }
 
   /*
